<?php
global $wpdb,$paged;
//?s=search-hotels&search-hotel-star=1&search-hotel-price=100&search-hotel-country=hotel-in-cambodia
if($search_hotel_star!="" && $search_hotel_price != "" && $search_hotel_country != "")
{
	$num_post	= 18;
	$post_type	= 'post';
	$taxonomy	= 'category';
	$field		= 'slug';
	$term		= $search_hotel_country;
	$metakey1			= $wpdb->prefix.'rating';
	$metavalue1			= $search_hotel_star;
	$metakey2			= $wpdb->prefix.'price';
	$metavalue2			= $search_hotel_price;	
	$args =  db_query_posts_in_terms_child_multi_paged($num_post,$post_type,$taxonomy,$field,$term,$metakey1,$metavalue1,$metakey2,$metavalue2,$paged);
	
}
else if($search_hotel_star!="" && $search_hotel_price == "" && $search_hotel_country == "")
{
	## 1 metakey
	$posts_per_page		= 18; 
	$post_type			= 'post'; 
	$orderby			= 'date'; 
	$order				= 'DESC'; 
	$meta_key			= $wpdb->prefix.'rating'; 
	$meta_value			= $search_hotel_star; 	
	$args = db_get_list_post_in_post_type_page_metakey($posts_per_page, $post_type, $orderby, $order, $meta_key, $meta_value, $paged);
}
else if($search_hotel_star =="" && $search_hotel_price != "" && $search_hotel_country == "")
{
	## 1 metakey
	$posts_per_page		= 18; 
	$post_type			= 'post'; 
	$orderby			= 'date'; 
	$order				= 'DESC'; 
	$meta_key			= $wpdb->prefix.'price'; 
	$meta_value			= $search_hotel_price; 	
	$args = db_get_list_post_in_post_type_page_metakey($posts_per_page, $post_type, $orderby, $order, $meta_key, $meta_value, $paged);
}
else if($search_hotel_star =="" && $search_hotel_price == "" && $search_hotel_country != "")
{
	## 1 taxonomy
	$num_post			=18;
	$post_type			= 'post';
	$taxonomy			= 'category';
	$field				= 'slug';
	$term				= $search_hotel_country;
	$metakey			= $wpdb->prefix.'display'; 
	$metavalue			= 'display';
	
	$args = db_query_posts_in_terms_child_paged($num_post,$post_type,$taxonomy,$field,$term,$metakey,$metavalue,$paged);
}
// 2 dau than
else if($search_hotel_star =="" && $search_hotel_price != "" && $search_hotel_country != "")
{
	## 1 metakey + 1 taxonomy
	$num_post			=18;
	$post_type			= 'post';
	$taxonomy			= 'category';
	$field				= 'slug';
	$term				= $search_hotel_country;
	$metakey			= $wpdb->prefix.'price'; 
	$metavalue			= $search_hotel_price;
	
	$args = db_query_posts_in_terms_child_paged($num_post,$post_type,$taxonomy,$field,$term,$metakey,$metavalue,$paged);	
}
else if($search_hotel_star !="" && $search_hotel_price == "" && $search_hotel_country != "")
{
	## 1 metakey + 1 taxonomy
	$num_post			=18;
	$post_type			= 'post';
	$taxonomy			= 'category';
	$field				= 'slug';
	$term				= $search_hotel_country;
	$metakey			= $wpdb->prefix.'rating'; 
	$metavalue			= $search_hotel_star;
	
	$args = db_query_posts_in_terms_child_paged($num_post,$post_type,$taxonomy,$field,$term,$metakey,$metavalue,$paged);
}
else if($search_hotel_star !="" && $search_hotel_price != "" && $search_hotel_country == "")
{
	## 1 metakey + 1 metakey
	$post_per_page			= 18;
	$post_type				= 'post';
	$order_by				= 'date';
	$order					= 'DESC';
	$meta_key1				= $wpdb->prefix.'rating';
	$meta_value1			= $search_hotel_star;
	$meta_key2				= $wpdb->prefix.'price';
	$meta_value2			= $search_hotel_price;
	
	$args = db_query_post_in_posttype_2meta_key_paged($post_per_page,$post_type,$order_by,$order,$meta_key1,$meta_value1,$meta_key2,$meta_value2,$paged);
}
query_posts($args);	
include TEMPLATEPATH.'/views/hotel/loop-hotel.php';